/*
 * @Author: szx
 * @Date: 2022-02-16 14:30:57
 * @LastEditTime: 2022-02-16 14:37:26
 * @Description:
 * @FilePath: \leetcode\900-999\977\977_2.js
 */
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortedSquares = function (nums) {
    const res = new Array(nums.length);
    let i = nums.length - 1;
    let left = 0,
        right = nums.length-1;
    while (left <= right) {
        const r = nums[right] ** 2;
        const l = nums[left] ** 2;
        if (l > r) {
            res[i--] = l;
            left++;
        } else {
            res[i--] = r;
            right--;
        }
    }
    return res;
};
console.log(sortedSquares([-7,-3,2,3,11]));
